//
//  ViewController.m
//  MATools
//
//  Created by mazb on 2021/9/3.
//

#import "ViewController.h"

@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>

@property(nonatomic, strong)UITableView *tableView;
@property(nonatomic, strong)NSMutableArray *dataArray;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor redColor];
    
    [self.view addSubview:self.tableView];
    
    
}

- (void)logoutNotification
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (NSMutableArray *)dataArray{
    if (! _dataArray) {
        _dataArray = @[@{@"title":@"HRBubbleView", @"subTitle": @"带箭头气泡", @"page":@"HRBubbleViewController"}];
    }
    return _dataArray;
}


- (UITableView *)tableView
{
    if (nil == _tableView) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
        _tableView.separatorInset = UIEdgeInsetsZero;
        _tableView.tableFooterView = [[UIView alloc] init];
    }
    
    return _tableView;
}


#pragma mark- uitableViewDelegate&datasource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *indentifier = @"TKPortfolioHoldingCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifier];
    }
    NSDictionary *dict = self.dataArray[indexPath.row];
    cell.textLabel.text = dict[@"title"];
    cell.detailTextLabel.text = dict[@"subTitle"];
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSDictionary *dict = self.dataArray[indexPath.row];
    NSString *selStr = dict[@"page"];
    
    Class class = NSClassFromString(selStr);
    UIViewController *v = [[class alloc] init];
    [self.navigationController pushViewController:v animated:YES];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
}

/*

- (UIViewController *)mx_topVC
{
    UIWindow *kW = nil;
    if (@available(iOS 13.0, *)) {
        for (UIWindowScene* windowScene in [UIApplication sharedApplication].connectedScenes)
        {
            if (windowScene.activationState == UISceneActivationStateForegroundActive)
            {
                kW = windowScene.windows.firstObject;

                break;
            }
        }
    }else{
        kW = [UIApplication sharedApplication].keyWindow;
    }
    
    UIViewController *topViewController = [kW rootViewController];
    
    while (true) {
        if (topViewController.presentedViewController)
        {
            topViewController = topViewController.presentedViewController;
            
        } else if ([topViewController isKindOfClass:[UINavigationController class]] && [(UINavigationController*)topViewController topViewController])
        {
            topViewController = [(UINavigationController *)topViewController topViewController];
            
        } else if ([topViewController isKindOfClass:[UITabBarController class]])
        {
            UITabBarController *tab = (UITabBarController *)topViewController;
            topViewController = tab.selectedViewController;
            
        } else {
            break;
        }
    }
    
    return topViewController;
}

*/

@end
